var express = require('express');
var path=require('path')
var app = express();

app.use('/public', express.static('public'));


// 直接访问  http://localhost:8081/index.htm
// path.sep是针对不同操作系统的路径分隔符
app.get('/index.htm', function (req, res) {
    res.sendFile( __dirname + path.sep + "index.html" );
})

app.get('/process_get', function (req, res) {

    // 输出 JSON 格式
    var response111 = {
        "first_name":req.query.first_name,
        "last_name":req.query.last_name
    };
    console.log(response111);
    // res.writeHead(200,{'Content-Type':'text/html;charset=utf-8'});//设置response编码为utf-8
    //这个和上面那个都可以,没有utf-8要乱码
    res.writeHead(200,{'Content-Type':'application/json;charset=utf-8'});
    res.end(JSON.stringify(response111));
})

var server = app.listen(8081, function () {

    var host = server.address().address
    var port = server.address().port

    console.log("应用实例，访问地址为 http://%s:%s", host, port)

})